package com.cljh.service.impl;

import com.cljh.bean.Distinct;
import com.cljh.controller.page.PageBean;
import com.cljh.controller.page.ProductPageBean;
import com.cljh.mapper.DistinctMapper;
import com.cljh.service.DistinctService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class DistinctServiceImpl implements DistinctService {
    @Autowired
    DistinctMapper distinctMapper;

    @Override
    public PageBean<Distinct> selectAllByCondition(Integer currentPage, Integer pageSize, Distinct distinct) {
        //计算开始索引
        int begin = (currentPage - 1) * pageSize;

        String productName = distinct.getProductName();
        if (productName!=null&&productName.length()>0) {
            distinct.setProductName("%" + productName + "%");
        }
        List<Distinct> distincts = distinctMapper.selectAllByCondition(begin, pageSize, distinct);
        int i = distinctMapper.selectByCount(distinct);
        PageBean<Distinct> distinctPageBean = new PageBean<>();
        distinctPageBean.setRows(distincts);
        distinctPageBean.setTotalCount(i);

        return distinctPageBean;
    }

    @Override
    public boolean save(Distinct distinct) {
        return distinctMapper.save(distinct)>0;
    }

    @Override
    public boolean delete(Integer id) {
        return distinctMapper.delete(id)>0;
    }

    @Override
    public boolean update(Distinct distinct) {
        return distinctMapper.upd(distinct)>0;
    }

    @Override
    public boolean deleteByIds(List<Integer> ids) {
        return distinctMapper.deleteByIds(ids)>0;
    }

    @Override
    public Distinct selectById(Integer id) {
        return distinctMapper.selectById(id);
    }

    @Override
    public List<Distinct> selectAll() {
        return distinctMapper.selectAll();
    }
}
